package com.biboheart.breport.engine.compile;

import com.biboheart.breport.template.BrTemplateNode;
import com.biboheart.brick.utils.CheckUtils;
import com.biboheart.brick.utils.MapUtils;
import org.mvel2.MVEL;

import java.util.Map;

public class ExtractorExpression implements Extractor {
    @Override
    public Object extract(Map<String, Object> input, BrTemplateNode templateNode) {
        String expression = templateNode.getExpression();
        if (CheckUtils.isEmpty(expression)) {
            return null;
        }
        try {
            return MVEL.eval(expression, input);
        } catch (Exception e) {
            System.out.println(expression + ":" + MapUtils.getValue(input, expression, String.class));
            return null;
        }
    }
}
